import os

import requests

from notify import send


def zhijiangbowuguan(filtered_datetime):
    filtered_datetimes=filtered_datetime.split(",")
    print(filtered_datetimes)
    flt=[]
    url = 'https://ticket.zhejiangmuseum.com/api/open/getIntervalSetting?venueId=4'
    heard = {
        'Host': 'ticket.zhejiangmuseum.com',
        'Connection': 'keep-alive',
        'Accept': 'application/json',
        'Referer': 'https://servicewechat.com/wx3655a33cec5430d9/22/page-frame.html',
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.42(0x18002a28) NetType/WIFI Language/zh_CN'
    }

    for i in filtered_datetimes:
        params = {
            'date' : i
        }
        response = requests.get(url, headers=heard,params=params)
        if response.status_code == 200:
            data = response.json()
            if '已' not in data["data"][0]['FormatInfo']+data["data"][1]['FormatInfo']:
                flt.append(i)
        else:
            return "数据异常或者黑IP"
    return flt

if __name__ == '__main__':
    datatime = os.getenv("zhijiangbowuguan")
    formatinfo=zhijiangbowuguan(datatime)
    print(formatinfo)
    if  formatinfo:
        send('之江博物馆有票啦',formatinfo)